home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / progba_1 / ctlprogb.ctl (.txt) next >
Encoding:
Visual Basic Form  |  1999-01-05  |  35.5 KB  |  829 lines

  1. VERSION 5.00
  2. Begin VB.UserControl ProgBar 
  3.    Alignable       =   -1  'True
  4.    BackColor       =   &H00FFFFFF&
  5.    CanGetFocus     =   0   'False
  6.    ClientHeight    =   1290
  7.    ClientLeft      =   0
  8.    ClientTop       =   0
  9.    ClientWidth     =   4425
  10.    ClipControls    =   0   'False
  11.    FillColor       =   &H00FF0000&
  12.    BeginProperty Font 
  13.       Name            =   "Arial"
  14.       Size            =   8.25
  15.       Charset         =   0
  16.       Weight          =   400
  17.       Underline       =   0   'False
  18.       Italic          =   0   'False
  19.       Strikethrough   =   0   'False
  20.    EndProperty
  21.    ForeColor       =   &H00FF0000&
  22.    ScaleHeight     =   86
  23.    ScaleMode       =   3  'Pixel
  24.    ScaleWidth      =   295
  25.    ToolboxBitmap   =   "ctlProgBar.ctx":0000
  26. Attribute VB_Name = "ProgBar"
  27. Attribute VB_GlobalNameSpace = False
  28. Attribute VB_Creatable = True
  29. Attribute VB_PredeclaredId = False
  30. Attribute VB_Exposed = False
  31. '===========================================================
  32. '= ProgBar Control V1.2.1                                  =
  33. '= ----------------------                                  =
  34. '= (C)1998 NE                                              =
  35. '= NE94252@netscape.net                                    =
  36. '=                                                         =
  37. '= You may use this source code within your own            =
  38. '= applications.  You may not distribute it on a website   =
  39. '= or ftp site without my express permission.              =
  40. '===========================================================
  41. '= Updates:                                                =
  42. '= --------                                                =
  43. '= V1.1          - Addition of the VerticalText property.  =
  44. '=               - General code clean up.                  =
  45. '=               - Addition of the ability to play a wav   =
  46. '=                 file at 100%.                           =
  47. '= V1.2          - Addition of gradient fill (BarStyle).   =
  48. '=               - All bar and background drawing handled  =
  49. '=                 by APIs to speed things up.             =
  50. '=               - The ability to wait for the sound to    =
  51. '=                 finish or not before realsing to code.  =
  52. '= V1.2.1        - Fixed a problem with the use of         =
  53. '=                 reserved words.                         =
  54. '===========================================================
  55. '= RunTime Properties: (Aphabetical order)                 =
  56. '= -------------------                                     =
  57. '= BackColour    - The back ground colour of the bar.      =
  58. '=                 Standard colour range.                  =
  59. '= BarEndColour  - The colour the bar fades into when the  =
  60. '=                 'BarStyle' is Gradient.                 =
  61. '=                 Standard colour range.                  =
  62. '= BarStartColour- The colour the bar fades from or the    =
  63. '=                 colour of the bar if the 'BarStyle' is  =
  64. '=                 Solid. Standard colour range.           =
  65. '= BarStyle      - The style of bar fill (gradient or      =
  66. '=                 solid).                                 =
  67. '=                 0 = Gradiant, 1 = Solid.                =
  68. '= BorderStyle   - Standard border style.                  =
  69. '=                 0 = Flat, 1 = ThreeD                    =
  70. '= FillDirection - The direction the bar should fill.      =
  71. '=                 0 = Up, 1 = Down, 2 = Left, 3 = Right   =
  72. '= FontColour    - The colour of the text displayed.       =
  73. '=                 Standard colour range.                  =
  74. '= Max           - The upper limit of the bar.             =
  75. '=                 Long value, -2147483648 to 2147483647   =
  76. '= Message       - The message to display in the bar.      =
  77. '=                 String.                                 =
  78. '= Min           - The lower limit of the progress bar.    =
  79. '=                 Long value, -2147483648 to 2147483647   =
  80. '= Percent       - The current bar percentage.             =
  81. '=                 Byte value, 0 to 100 (obviously :))     =
  82. '= PlaySound     - Flag to indicate the sound file         =
  83. '=                 specified in the SoundToPlay property   =
  84. '=                 sould be played when 100% is reached.   =
  85. '=                 (TRUE, FALSE)                           =
  86. '= ShowMessage   - Flag to indicate the message should be  =
  87. '=                 shown. (TRUE, FALSE)                    =
  88. '= ShowPercent   - Flag to incicate the current percentage =
  89. '=                 should be shown. (TRUE, FALSE)          =
  90. '= ShowValue     - Flag to indicate the current value      =
  91. '=                 should be shown. (TRUE, FALSE)          =
  92. '= SoundToPlay   - A string value holding the path and     =
  93. '=                 name of the wav file to play @ 100%.    =
  94. '= Value         - The current value of the progress bar.  =
  95. '=                 Long value, -2147483648 to 2147483647   =
  96. '= VerticalText  - Flag to indicate that the text should   =
  97. '=                 be written top to bottom, useful for up =
  98. '=                 or down progress bars. (TRUE, FALSE)    =
  99. '= WaitForSound  - This flag indicates that the code will  =
  100. '=                 susspend until the sound file played at =
  101. '=                 100% has finished playing.  If one's    =
  102. '=                 set to play that is. (TRUE, FALSE)      =
  103. '===========================================================
  104. '= Notes:                                                  =
  105. '= ------                                                  =
  106. '= 1. You can either show the percentage or value or       =
  107. '=    neither.  You can't show both.  Setting one will     =
  108. '=    disable the other.                                   =
  109. '= 2. Setting the value above the 'Max' or below the 'Min' =
  110. '=    will result in the value being set to the 'Max' or   =
  111. '=    'Min'.                                               =
  112. '= 3. Setting the percent above 100 or below 0 will result =
  113. '=    in the percentage being changed.                     =
  114. '= 4. Setting the 'Max' below the 'Min' will result in the =
  115. '=    'Max' being set to the 'Min' + 1.                    =
  116. '= 5. Setting the 'Min' below the 'Max' will result in the =
  117. '=    'Min' being set to the 'Max' - 1.                    =
  118. '= 6. Adjusting either the 'Max' or the 'Min' will cause   =
  119. '=    the 'Value' to be recalculated.                      =
  120. '= 7. If the 'BarStyle' is set to solid the colour of the  =
  121. '=    bar is defined by the 'BarStartColour' property.     =
  122. '= 8. If a sound is playing and the flag to play one at    =
  123. '=    100% is set the currently playing file will stop and =
  124. '=    the specified one will play.                         =
  125. '===========================================================
  126. '= Have fun! NE                                            =
  127. '===========================================================
  128. Option Explicit
  129. 'API and constant to play wav file.
  130. Private Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
  131. Private Const SND_SYNC = &H0
  132. Private Const SND_ASYNC = &H1
  133. 'API's, type and constants for the bar fills.
  134. Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
  135. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  136. Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, ByVal nIndex As Long) As Long
  137. Private Declare Function FillRect Lib "user32" (ByVal hDC As Long, lpRect As RECT, ByVal hBrush As Long) As Long
  138. Private Type RECT
  139.     vLeft    As Long
  140.     vTop     As Long
  141.     vRight   As Long
  142.     vBottom  As Long
  143. End Type
  144. Private Const PLANES = 14
  145. Private Const BITSPIXEL = 12
  146. 'Fill direction list.
  147. Public Enum FillDirection
  148.     pbUp
  149.     pbDown
  150.     pbLeft
  151.     pbRight
  152. End Enum
  153. 'Border style list.
  154. Public Enum BorderStyles
  155.     pbNone
  156.     pbFixedSingle
  157. End Enum
  158. 'Appearance style list.
  159. Public Enum AppearanceStyles
  160.     pbFlat
  161.     pbThreeD
  162. End Enum
  163. 'Bar style list.
  164. Public Enum BarStyle
  165.     pbGradient
  166.     pbSolid
  167. End Enum
  168. 'Local variables to hold property values.
  169. Private mvarPercent As Byte
  170. Private mvarMin As Long
  171. Private mvarMax As Long
  172. Private mvarValue As Long
  173. Private mvarShowPercent As Boolean
  174. Private mvarMessage As String
  175. Private mvarShowMessage As Boolean
  176. Private mvarBarStartColour As OLE_COLOR
  177. Private mvarBarEndColour As OLE_COLOR
  178. Private mvarShowValue As Boolean
  179. Private mvarFillDirection As FillDirection
  180. Private mvarBackColour As OLE_COLOR
  181. Private mvarSoundToPlay As String
  182. Private mvarPlaySound As Boolean
  183. Private mvarVerticalText As Boolean
  184. Private mvarBarStyle As BarStyle
  185. Private mvarWaitForSound As Boolean
  186. 'Default property values.
  187. Const mdefPercent = 0               'Start percent.
  188. Const mdefMin = 0                   'Lower limit.
  189. Const mdefMax = 100                 'Upper limit.
  190. Const mdefValue = 0                 'Start value.
  191. Const mdefShowPercent = False       'Don't show the percentage.
  192. Const mdefMessage = ""              'No start message.
  193. Const mdefShowMessage = False       'Don't show the message.
  194. Const mdefBarStartColour = &HFF     'Red bar colour start.
  195. Const mdefBarEndColour = &H0        'Black bar colour end.
  196. Const mdefShowValue = False         'Don't show the value.
  197. Const mdefFillDirection = 3         'Right fill.
  198. Const mdefBackColour = &HFFFFFF     'White background.
  199. Const mdefBorderStyle = 1           'ThreeD border style.
  200. Const mdefFontColour = &HFF0000     'Blue Text.
  201. Const mdefVerticalText = False      'Normal left to right text.
  202. Const mdefSoundToPlay = ""          'No initial sound.
  203. Const mdefPlaySound = False         'Don't play sound.
  204. Const mdefBarStyle = 1              'Solid.
  205. Const mdefWaitForSound = False      'Don't bother waiting.
  206. Public Property Let WaitForSound(ByVal vData As Boolean)
  207.     'Set the wait for sound property.
  208.     mvarWaitForSound = vData
  209.     'Indicate a property change.
  210.     PropertyChanged "WaitForSound"
  211. End Property
  212. Public Property Get WaitForSound() As Boolean
  213.     'Get the current state of the wait for sound flag.
  214.     WaitForSound = mvarWaitForSound
  215. End Property
  216. Public Property Let BarStyle(ByVal vData As BarStyle)
  217.     'Check the bar style chosen, if it's outside the available
  218.     'settings set it to Solid.
  219.     If vData < 0 Or vData > 1 Then vData = 1
  220.     'Set the bar style.
  221.     mvarBarStyle = vData
  222.     'Update the control.
  223.     UserControl_Paint
  224.     'Indicate a property change.
  225.     PropertyChanged "BarStyle"
  226. End Property
  227. Public Property Get BarStyle() As BarStyle
  228.     'Get the current barstyle property value.
  229.     BarStyle = mvarBarStyle
  230. End Property
  231. Public Property Let VerticalText(ByVal vData As Boolean)
  232.     'Set the vertical text flag.
  233.     mvarVerticalText = vData
  234.     'Update the control.
  235.     UserControl_Paint
  236.     'Indicate a property change.
  237.     PropertyChanged "VerticalText"
  238. End Property
  239. Public Property Get VerticalText() As Boolean
  240.     'Get the state of the vertical text flag.
  241.     VerticalText = mvarVerticalText
  242. End Property
  243. Public Property Let SoundToPlay(ByVal vData As String)
  244.     'Set the sound to play file string.
  245.     mvarSoundToPlay = vData
  246.     'Indicate a property change.
  247.     PropertyChanged "SoundToPlay"
  248. End Property
  249. Public Property Get SoundToPlay() As String
  250.     'Get the surrent sound file string.
  251.     SoundToPlay = mvarSoundToPlay
  252. End Property
  253. Public Property Let PlaySound(ByVal vData As Boolean)
  254.     'Set the play sound flag.
  255.     mvarPlaySound = vData
  256.     'Indicate a property change.
  257.     PropertyChanged "PlaySound"
  258. End Property
  259. Public Property Get PlaySound() As Boolean
  260.     'Get the current play sound flag.
  261.     PlaySound = mvarPlaySound
  262. End Property
  263. Public Property Let FontColour(ByVal vData As OLE_COLOR)
  264.     'Set the font colour by changing the forecolor.
  265.     UserControl.ForeColor = vData
  266.     'Update the control.
  267.     UserControl_Paint
  268.     'Indicate a property change.
  269.     PropertyChanged "FontColour"
  270. End Property
  271. Private Property Get FontColour() As OLE_COLOR
  272.     'Get the current font colour.
  273.     FontColour = UserControl.ForeColor
  274. End Property
  275. Public Property Let BorderStyle(ByVal vData As BorderStyles)
  276.     'Set the border style for the progress bar.
  277.     If vData < 0 Then
  278.         vData = 0
  279.     ElseIf vData > 1 Then
  280.         vData = 1
  281.     End If
  282.     UserControl.BorderStyle = vData
  283.     'Update the control.
  284.     UserControl_Paint
  285.     'Indicate a property change.
  286.     PropertyChanged "BorderStyle"
  287. End Property
  288. Public Property Get BorderStyle() As BorderStyles
  289.     'Get the current border style.
  290.     BorderStyle = UserControl.BorderStyle
  291. End Property
  292. Public Property Let BarStartColour(ByVal vData As OLE_COLOR)
  293.     'Set the bar start colour value.
  294.     mvarBarStartColour = vData
  295.     'Update the control.
  296.     UserControl_Paint
  297.     'Indicate a property change.
  298.     PropertyChanged "BarStartColour"
  299. End Property
  300. Public Property Get BarStartColour() As OLE_COLOR
  301.     'Return the start colour value.
  302.     BarStartColour = mvarBarStartColour
  303. End Property
  304. Public Property Let BarEndColour(ByVal vData As OLE_COLOR)
  305.     'Set the bar end colour.
  306.     mvarBarEndColour = vData
  307.     'Update the control.
  308.     UserControl_Paint
  309.     'Indicate a property change.
  310.     PropertyChanged "BarEndColour"
  311. End Property
  312. Public Property Get BarEndColour() As OLE_COLOR
  313.     'Return the end bar colour.
  314.     BarEndColour = mvarBarEndColour
  315. End Property
  316. Public Property Let BackColour(ByVal vData As OLE_COLOR)
  317.     'Set the back colour.
  318.     mvarBackColour = vData
  319.     'Update the control.
  320.     UserControl_Paint
  321.     'Indicate a property change.
  322.     PropertyChanged "BackColour"
  323. End Property
  324. Public Property Get BackColour() As OLE_COLOR
  325.     'Get the current back colour.
  326.     BackColour = mvarBackColour
  327. End Property
  328. Public Property Let Value(ByVal vData As Long)
  329. Attribute Value.VB_Description = "Returns/sets the value on the progress bar."
  330.     'Make sure the value chosen resides in the set range.
  331.     If vData < mvarMin Then
  332.         vData = mvarMin
  333.     ElseIf vData > mvarMax Then
  334.         vData = mvarMax
  335.     End If
  336.     'Set the current progress bar value.
  337.     mvarValue = vData
  338.     'Calculate the percentage.
  339.     mvarPercent = Int(((mvarValue - mvarMin) / (mvarMax - mvarMin)) * 100)
  340.     'Update the control.
  341.     UserControl_Paint
  342.     'Indicate property changes.
  343.     PropertyChanged "Value"
  344.     PropertyChanged "Percent"
  345. End Property
  346. Public Property Get Value() As Long
  347.     'Return the current value.
  348.     Value = mvarValue
  349. End Property
  350. Public Property Let Min(ByVal vData As Long)
  351. Attribute Min.VB_Description = "Returns/sets the progress bars lower limit."
  352.     'Check the min value is at least 1 less than
  353.     'the max value
  354.     If vData >= mvarMax Then vData = mvarMax - 1
  355.     'Set the start value of the progress bar.
  356.     mvarMin = vData
  357.     'Recalculate the value.
  358.     mvarValue = Int(((mvarPercent / 100) * (mvarMax - mvarMin)) + mvarMin)
  359.     'Update the control.
  360.     UserControl_Paint
  361.     'Indicate property changes.
  362.     PropertyChanged "Min"
  363.     PropertyChanged "Value"
  364. End Property
  365. Public Property Get Min() As Long
  366.     'Return the value of the start.
  367.     Min = mvarMin
  368. End Property
  369. Public Property Let ShowValue(ByVal vData As Boolean)
  370. Attribute ShowValue.VB_Description = "Returns/sets the flag to indicate the value should be shown."
  371.     'Set the flag to indicate the value should be shown
  372.     'in the progress bar.
  373.     mvarShowValue = vData
  374.     'Check to see if the percentage is set to show in the
  375.     'progress bar and disable it.
  376.     If mvarShowValue = True Then
  377.         mvarShowPercent = False
  378.         'Indicate a property change.
  379.         PropertyChanged "ShowPercent"
  380.     End If
  381.     'Update the control.
  382.     UserControl_Paint
  383.     'Indicate a property change.
  384.     PropertyChanged "ShowValue"
  385. End Property
  386. Public Property Get ShowValue() As Boolean
  387.     'Return the current state of the value show flag.
  388.     ShowValue = mvarShowValue
  389. End Property
  390. Public Property Let ShowPercent(ByVal vData As Boolean)
  391. Attribute ShowPercent.VB_Description = "Returns/sets the flag to indicate the percentage should be shown."
  392.     'Set the flag to indicate the percentage should be shown
  393.     'in the progress bar.
  394.     mvarShowPercent = vData
  395.     'Check to see if the value is set to be shown and
  396.     'disable it.
  397.     If mvarShowPercent = True Then
  398.         mvarShowValue = False
  399.         'Indicate a property change.
  400.         PropertyChanged "ShowValue"
  401.     End If
  402.     'Update the control.
  403.     UserControl_Paint
  404.     'Indicate a property change.
  405.     PropertyChanged "ShowPercent"
  406. End Property
  407. Public Property Get ShowPercent() As Boolean
  408.     'Return the flag state for the percent showing.
  409.     ShowPercent = mvarShowPercent
  410. End Property
  411. Public Property Let ShowMessage(ByVal vData As Boolean)
  412. Attribute ShowMessage.VB_Description = "Returns/sets the flag to indicate the message should be shown."
  413.     'Set the flag to indicate the message should be shown.
  414.     mvarShowMessage = vData
  415.     'Update the control.
  416.     UserControl_Paint
  417.     'Indicate a property change.
  418.     PropertyChanged "ShowMessage"
  419. End Property
  420. Public Property Get ShowMessage() As Boolean
  421.     'Return the show message flag.
  422.     ShowMessage = mvarShowMessage
  423. End Property
  424. Public Property Let Percent(ByVal vData As Byte)
  425. Attribute Percent.VB_Description = "Returns/sets the percentage on the progress bar."
  426.     'Ensure the percent chosen is between 0 and 100.
  427.     If vData < 0 Then
  428.         vData = 0
  429.     ElseIf vData > 100 Then
  430.         vData = 100
  431.     End If
  432.     'Set the percent property.
  433.     mvarPercent = vData
  434.     'Calculate the value.
  435.     mvarValue = Int(((mvarPercent / 100) * (mvarMax - mvarMin)) + mvarMin)
  436.     'Update the control.
  437.     UserControl_Paint
  438.     'Indicate property changes.
  439.     PropertyChanged "Percent"
  440.     PropertyChanged "Value"
  441. End Property
  442. Public Property Get Percent() As Byte
  443.     'Return the current percentage of the progress bar.
  444.     Percent = mvarPercent
  445. End Property
  446. Public Property Let Message(ByVal vData As String)
  447.     'Set message to show in the progress bar.
  448.     mvarMessage = vData
  449.     'Update the control.
  450.     UserControl_Paint
  451.     'Indicate a property change.
  452.     PropertyChanged "Message"
  453. End Property
  454. Public Property Get Message() As String
  455.     'Return the message to show.
  456.     Message = mvarMessage
  457. End Property
  458. Public Property Let Max(ByVal vData As Long)
  459.     'Check that the max value is at least 1 higher than
  460.     'the minimum value.
  461.     If vData <= mvarMin Then vData = mvarMin + 1
  462.     'Set the finish value for the progress bar.
  463.     mvarMax = vData
  464.     'Recalculate the value.
  465.     mvarValue = Int(((mvarPercent / 100) * (mvarMax - mvarMin)) + mvarMin)
  466.     'Update the control.
  467.     UserControl_Paint
  468.     'Indicate property changes.
  469.     PropertyChanged "Max"
  470.     PropertyChanged "Value"
  471. End Property
  472. Public Property Get Max() As Long
  473.     'Return the finish value.
  474.     Max = mvarMax
  475. End Property
  476. Public Property Let FillDirection(ByVal vData As FillDirection)
  477. Attribute FillDirection.VB_Description = "Returns/sets the the fill direction of the progress bar."
  478.     'Set the direction of the fill to right if it's invalid.
  479.     If vData < 0 Or vData > 3 Then
  480.         vData = 3
  481.     End If
  482.     'Save the setting in the property variable.
  483.     mvarFillDirection = vData
  484.     'Update the control.
  485.     UserControl_Paint
  486.     'Indicate a property change.
  487.     PropertyChanged "FillDirection"
  488. End Property
  489. Public Property Get FillDirection() As FillDirection
  490.     'Return the current fill direction.
  491.     FillDirection = mvarFillDirection
  492. End Property
  493. Private Sub UserControl_InitProperties()
  494.     'Set the defaults.
  495.     mvarFillDirection = mdefFillDirection
  496.     mvarMin = mdefMin
  497.     mvarMax = mdefMax
  498.     mvarValue = mdefValue
  499.     mvarPercent = mdefPercent
  500.     mvarMessage = mdefMessage
  501.     mvarShowMessage = mdefShowMessage
  502.     mvarShowPercent = mdefShowPercent
  503.     mvarShowValue = mdefShowValue
  504.     UserControl.BorderStyle = mdefBorderStyle
  505.     mvarBackColour = mdefBackColour
  506.     mvarBarStartColour = mdefBarStartColour
  507.     mvarBarEndColour = mdefBarEndColour
  508.     UserControl.ForeColor = mdefFontColour
  509.     mvarVerticalText = mdefVerticalText
  510.     mvarSoundToPlay = mdefSoundToPlay
  511.     mvarPlaySound = mdefPlaySound
  512.     mvarBarStyle = mdefBarStyle
  513.     mvarWaitForSound = mdefWaitForSound
  514. End Sub
  515. Private Sub UserControl_Paint()
  516.     'Draw the bar.
  517.     DrawBar
  518.     'Draw the text.
  519.     DrawText
  520.     'Play the wav file.
  521.     PlayWav
  522. End Sub
  523. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  524.     'Restore the saved properties.
  525.     mvarBackColour = PropBag.ReadProperty("BackColour", mdefBackColour)
  526.     mvarBarStartColour = PropBag.ReadProperty("BarStartColour", mdefBarStartColour)
  527.     mvarBarEndColour = PropBag.ReadProperty("BarEndColour", mdefBarEndColour)
  528.     mvarFillDirection = PropBag.ReadProperty("FillDirection", mdefFillDirection)
  529.     mvarMax = PropBag.ReadProperty("Max", mdefMax)
  530.     mvarMessage = PropBag.ReadProperty("Message", mdefMessage)
  531.     mvarMin = PropBag.ReadProperty("Min", mdefMin)
  532.     mvarPercent = PropBag.ReadProperty("Percent", mdefPercent)
  533.     mvarShowMessage = PropBag.ReadProperty("ShowMessage", mdefShowMessage)
  534.     mvarShowPercent = PropBag.ReadProperty("ShowPercent", mdefShowPercent)
  535.     mvarShowValue = PropBag.ReadProperty("ShowValue", mdefShowValue)
  536.     mvarValue = PropBag.ReadProperty("Value", mdefValue)
  537.     mvarVerticalText = PropBag.ReadProperty("VerticalText", mdefVerticalText)
  538.     UserControl.BorderStyle = PropBag.ReadProperty("BorderStyle", mdefBorderStyle)
  539.     UserControl.ForeColor = PropBag.ReadProperty("FontColour", mdefFontColour)
  540.     mvarSoundToPlay = PropBag.ReadProperty("SoundToPlay", mdefSoundToPlay)
  541.     mvarPlaySound = PropBag.ReadProperty("PlaySound", mdefPlaySound)
  542.     mvarBarStyle = PropBag.ReadProperty("BarStyle", mdefBarStyle)
  543.     mvarWaitForSound = PropBag.ReadProperty("WaitForSound", mdefWaitForSound)
  544. End Sub
  545. Private Sub UserControl_Resize()
  546.     'Repaint the control.
  547.     UserControl_Paint
  548. End Sub
  549. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  550.     'Save the instances current properties.
  551.     PropBag.WriteProperty "BackColour", mvarBackColour, mdefBackColour
  552.     PropBag.WriteProperty "BarStartColour", mvarBarStartColour, mdefBarStartColour
  553.     PropBag.WriteProperty "BarEndColour", mvarBarEndColour, mdefBarEndColour
  554.     PropBag.WriteProperty "BorderStyle", UserControl.BorderStyle, mdefBorderStyle
  555.     PropBag.WriteProperty "FillDirection", mvarFillDirection, mdefFillDirection
  556.     PropBag.WriteProperty "FontColour", UserControl.ForeColor, mdefFontColour
  557.     PropBag.WriteProperty "Max", mvarMax, mdefMax
  558.     PropBag.WriteProperty "Message", mvarMessage, mdefMessage
  559.     PropBag.WriteProperty "Min", mvarMin, mdefMin
  560.     PropBag.WriteProperty "Percent", mvarPercent, mdefPercent
  561.     PropBag.WriteProperty "ShowMessage", mvarShowMessage, mdefShowMessage
  562.     PropBag.WriteProperty "ShowPercent", mvarShowPercent, mdefShowPercent
  563.     PropBag.WriteProperty "ShowValue", mvarShowValue, mdefShowValue
  564.     PropBag.WriteProperty "Value", mvarValue, mdefValue
  565.     PropBag.WriteProperty "VerticalText", mvarVerticalText, mdefVerticalText
  566.     PropBag.WriteProperty "SoundToPlay", mvarSoundToPlay, mdefSoundToPlay
  567.     PropBag.WriteProperty "PlaySound", mvarPlaySound, mdefPlaySound
  568.     PropBag.WriteProperty "BarStyle", mvarBarStyle, mdefBarStyle
  569.     PropBag.WriteProperty "WaitForSound", mvarWaitForSound, mdefWaitForSound
  570. End Sub
  571. Private Sub DrawBar()
  572.     'Local variables (a few eh?:)).
  573.     Static lngColourBits As Long
  574.     Static intRgnCnt As Integer
  575.     Dim lngNbrPlanes As Long
  576.     Dim lngBitsPerPixel As Long
  577.     Dim lngAreaHeight As Long
  578.     Dim lngAreaWidth As Long
  579.     Dim sngRedLevel As Single
  580.     Dim sngGreenLevel As Single
  581.     Dim sngBlueLevel As Single
  582.     Dim sngRedColourVal As Single
  583.     Dim sngGreenColourVal As Single
  584.     Dim sngBlueColourVal As Single
  585.     Dim dblIntervalY As Double
  586.     Dim dblIntervalX As Double
  587.     Dim dblCurrentY As Double
  588.     Dim dblCurrentX As Double
  589.     Dim i As Integer
  590.     Dim r As Long
  591.     Dim FillArea As RECT
  592.     Dim hBrush As Long
  593.     'Init code - performed only on the first pass through this routine.
  594.     If lngColourBits = 0 Then
  595.         'Determine number of color bits supported.
  596.         lngBitsPerPixel = GetDeviceCaps(UserControl.hDC, BITSPIXEL)
  597.         lngNbrPlanes = GetDeviceCaps(UserControl.hDC, PLANES)
  598.         lngColourBits = (lngBitsPerPixel * lngNbrPlanes)
  599.         'Calculate the number of regions that the screen will be divided into.
  600.         'This is optimized for the current display's color depth.  Why waste
  601.         'time rendering 256 shades if you can only discern 32 or 64 of them?
  602.         Select Case lngColourBits
  603.             Case 32:   intRgnCnt = 256     '16M colors:  8 bits for blue
  604.             Case 24:   intRgnCnt = 256     '16M colors:  8 bits for blue
  605.             Case 16:   intRgnCnt = 256     '64K colors:  5 bits for blue
  606.             Case 15:   intRgnCnt = 32      '32K colors:  5 bits for blue
  607.             Case 8:    intRgnCnt = 64      '256 colors:  64 dithered blues
  608.             Case 4:    intRgnCnt = 64      '16 colors :  64 dithered blues
  609.             Case Else: lngColourBits = 4
  610.                 intRgnCnt = 64      '16 colors assumed: 64 dithered blues
  611.         End Select
  612.     End If
  613.     'Get the current pixel sizes.
  614.     lngAreaHeight = UserControl.ScaleHeight
  615.     lngAreaWidth = UserControl.ScaleWidth
  616.     'Determine start colour levels.
  617.     sngRedLevel = mvarBarStartColour And &HFF&
  618.     sngGreenLevel = (mvarBarStartColour And &HFF00&) \ &H100&
  619.     sngBlueLevel = (mvarBarStartColour And &HFF0000) \ &H10000
  620.        
  621.     'Set the fill area to the entire bar.
  622.     FillArea.vLeft = 0
  623.     FillArea.vTop = 0
  624.     FillArea.vRight = lngAreaWidth
  625.     FillArea.vBottom = lngAreaHeight
  626.     'If the bar is solid adjust the fill area depending upon
  627.     'what type of fill it is.
  628.     If mvarBarStyle = 1 Then
  629.         Select Case mvarFillDirection
  630.             Case 0 'UP
  631.                 FillArea.vTop = lngAreaHeight - ((lngAreaHeight / 100) * mvarPercent)
  632.             Case 1 'DOWN
  633.                 FillArea.vBottom = (lngAreaHeight / 100) * mvarPercent
  634.             Case 2 'LEFT
  635.                 FillArea.vLeft = lngAreaWidth - ((lngAreaWidth / 100) * mvarPercent)
  636.             Case 3 'RIGHT
  637.                 FillArea.vRight = (lngAreaWidth / 100) * mvarPercent
  638.         End Select
  639.         'Fill the defined area with the start colour.
  640.         hBrush = CreateSolidBrush(RGB(sngRedLevel, sngGreenLevel, sngBlueLevel))
  641.         r = FillRect(UserControl.hDC, FillArea, hBrush)
  642.         r = DeleteObject(hBrush)
  643.     'If it's a gradient run this code.
  644.     Else
  645.         'Number of pixels per region.
  646.         dblIntervalY = lngAreaHeight / intRgnCnt
  647.         dblIntervalX = lngAreaWidth / intRgnCnt
  648.         'Colour difference between regions.
  649.         sngRedColourVal = ((mvarBarEndColour And &HFF&) - sngRedLevel) / intRgnCnt
  650.         sngGreenColourVal = (((mvarBarEndColour And &HFF00&) \ &H100&) - sngGreenLevel) / intRgnCnt
  651.         sngBlueColourVal = (((mvarBarEndColour And &HFF0000) \ &H10000) - sngBlueLevel) / intRgnCnt
  652.         'Work through the number of regions the bar has been split into.
  653.         For i = 0 To intRgnCnt - 1
  654.             'Create a brush of the appropriate colour.
  655.             hBrush = CreateSolidBrush(RGB(Int(sngRedLevel), Int(sngGreenLevel), Int(sngBlueLevel)))
  656.             'Select the appropriate fill direction.
  657.             Select Case mvarFillDirection
  658.                 Case 0 'UP
  659.                     'Adjust the fill area to the current region.
  660.                     FillArea.vTop = lngAreaHeight - dblCurrentY - dblIntervalY
  661.                     FillArea.vBottom = lngAreaHeight - dblCurrentY
  662.                     'Fill this area if the area is shown, otherwise exit the loop.
  663.                     If FillArea.vTop > lngAreaHeight - ((lngAreaHeight / 100) * mvarPercent) Then
  664.                         r = FillRect(UserControl.hDC, FillArea, hBrush)
  665.                     Else
  666.                         Exit For
  667.                     End If
  668.                 Case 1 'DOWN
  669.                     'Adjust the fill area to the current region.
  670.                     FillArea.vTop = dblCurrentY
  671.                     FillArea.vBottom = dblCurrentY + dblIntervalY
  672.                     'Fill this area if the area is shown, otherwise exit the loop.
  673.                     If FillArea.vBottom < (lngAreaHeight / 100) * mvarPercent Then
  674.                         r = FillRect(UserControl.hDC, FillArea, hBrush)
  675.                     Else
  676.                         Exit For
  677.                     End If
  678.                 Case 2 'LEFT
  679.                     'Adjust the fill area to the current region.
  680.                     FillArea.vLeft = lngAreaWidth - dblCurrentX - dblIntervalX
  681.                     FillArea.vRight = lngAreaWidth - dblCurrentX
  682.                     'Fill this area if the area is shown, otherwise exit the loop.
  683.                     If FillArea.vLeft > lngAreaWidth - ((lngAreaWidth / 100) * mvarPercent) Then
  684.                         r = FillRect(UserControl.hDC, FillArea, hBrush)
  685.                     Else
  686.                         Exit For
  687.                     End If
  688.                 Case 3 'RIGHT
  689.                     'Adjust the fill area to the current region.
  690.                     FillArea.vLeft = dblCurrentX
  691.                     FillArea.vRight = dblCurrentX + dblIntervalX
  692.                     'Fill this area if the area is shown, otherwise exit the loop.
  693.                     If FillArea.vRight < (lngAreaWidth / 100) * mvarPercent Then
  694.                         r = FillRect(UserControl.hDC, FillArea, hBrush)
  695.                     Else
  696.                         Exit For
  697.                     End If
  698.             End Select
  699.             'Done with that brush, so delete it.
  700.             r = DeleteObject(hBrush)
  701.             'Increment the current X and Y locations.
  702.             dblCurrentY = dblCurrentY + dblIntervalY
  703.             dblCurrentX = dblCurrentX + dblIntervalX
  704.             'Increment display colour depth.
  705.             sngRedLevel = sngRedLevel + sngRedColourVal
  706.             sngGreenLevel = sngGreenLevel + sngGreenColourVal
  707.             sngBlueLevel = sngBlueLevel + sngBlueColourVal
  708.         Next
  709.         'Check to see if we bailed out of the for loop, if so
  710.         'delete the brush.
  711.         If i < intRgnCnt - 1 Then
  712.             r = DeleteObject(hBrush)
  713.         Else
  714.             'If we're at the end of the bar.
  715.             'Fill any of the remaining spaces with the end colour.
  716.             Select Case mvarFillDirection
  717.                 Case 0 'UP
  718.                     FillArea.vTop = 0
  719.                     FillArea.vBottom = FillArea.vTop + dblIntervalY
  720.                 Case 1 'DOWN
  721.                     FillArea.vBottom = lngAreaHeight
  722.                     FillArea.vTop = FillArea.vBottom - dblIntervalY
  723.                 Case 2 'LEFT
  724.                     FillArea.vLeft = 0
  725.                     FillArea.vRight = FillArea.vLeft + dblIntervalX
  726.                 Case 3 'RIGHT
  727.                     FillArea.vRight = lngAreaWidth
  728.                     FillArea.vLeft = FillArea.vRight - dblIntervalX
  729.             End Select
  730.             hBrush = CreateSolidBrush(RGB(mvarBarEndColour And &HFF&, (mvarBarEndColour And &HFF00&) \ &H100&, (mvarBarEndColour And &HFF0000) \ &H10000))
  731.             r = FillRect(UserControl.hDC, FillArea, hBrush)
  732.             r = DeleteObject(hBrush)
  733.         End If
  734.     End If
  735.     'Draw the background if there's one to draw.
  736.     If mvarPercent < 100 Then
  737.         Select Case mvarFillDirection
  738.             Case 0 'UP
  739.                 FillArea.vTop = 0
  740.                 FillArea.vBottom = lngAreaHeight - ((lngAreaHeight / 100) * mvarPercent)
  741.             Case 1 'DOWN
  742.                 FillArea.vTop = (lngAreaHeight / 100) * mvarPercent
  743.                 FillArea.vBottom = lngAreaHeight
  744.             Case 2 'LEFT
  745.                 FillArea.vLeft = 0
  746.                 FillArea.vRight = lngAreaWidth - ((lngAreaWidth / 100) * mvarPercent)
  747.             Case 3 'RIGHT
  748.                 FillArea.vLeft = (lngAreaWidth / 100) * mvarPercent
  749.                 FillArea.vRight = lngAreaWidth
  750.         End Select
  751.         'Fill the defined area with the background colour.
  752.         hBrush = CreateSolidBrush(RGB(mvarBackColour And &HFF&, (mvarBackColour And &HFF00&) \ &H100&, (mvarBackColour And &HFF0000) \ &H10000))
  753.         r = FillRect(UserControl.hDC, FillArea, hBrush)
  754.         r = DeleteObject(hBrush)
  755.     End If
  756. End Sub
  757. Private Sub DrawText()
  758.     'Local variables.
  759.     Dim txtBarTxt As String
  760.     Dim i As Integer
  761.     Dim dblVertCurrentY As Double
  762.     'If we want to show any text then draw it.
  763.     If mvarShowMessage Or mvarShowPercent Or mvarShowValue Then
  764.         'Reset to user defined scalemode for the text.
  765.         UserControl.ScaleHeight = 100
  766.         UserControl.ScaleWidth = 100
  767.         'Set message if there's one flagged to show.
  768.         If mvarShowMessage Then txtBarTxt = mvarMessage
  769.         'Add the percent or value if either are flagged to show.
  770.         If mvarShowPercent Or mvarShowValue Then
  771.             'Add a space if the percentage or value is to be shown and there is a message.
  772.             If Len(txtBarTxt) > 0 Then txtBarTxt = txtBarTxt & " "
  773.             'Add the percentage if it's flagged to show.
  774.             If mvarShowPercent Then
  775.                 txtBarTxt = txtBarTxt & Format$(mvarPercent, "##0") + "%"
  776.             'Add the value if it's flagged to show.
  777.             ElseIf mvarShowValue Then
  778.                 txtBarTxt = txtBarTxt & Trim(Str(mvarValue)) & "/" & Trim(Str(mvarMax))
  779.             End If
  780.         End If
  781.         'Draw the text vertically is so flagged.
  782.         If mvarVerticalText Then
  783.             'Calculate the total height of all the text.
  784.             For i = 1 To Len(txtBarTxt)
  785.                 dblVertCurrentY = dblVertCurrentY + UserControl.TextHeight(Mid(txtBarTxt, i, 1))
  786.             Next i
  787.             'Set the Y coord to the begining letter of the text.
  788.             dblVertCurrentY = (100 - dblVertCurrentY) / 2
  789.             'Work through each letter of the text and place it on the progress bar.
  790.             For i = 1 To Len(txtBarTxt)
  791.                 'Set Y coord to put the letter.
  792.                 UserControl.CurrentY = dblVertCurrentY
  793.                 'Move the Y coord pointer for the next letter.
  794.                 dblVertCurrentY = dblVertCurrentY + UserControl.TextHeight(Mid(txtBarTxt, i, 1))
  795.                 'Get X coord to put the letter.
  796.                 UserControl.CurrentX = 50 - UserControl.TextWidth(Mid(txtBarTxt, i, 1)) / 2
  797.                 'Print bar letter.
  798.                 UserControl.Print Mid(txtBarTxt, i, 1)
  799.             Next i
  800.         'Otherwise draw the text the normal left to right.
  801.         Else
  802.             'Get Y coord to put the text.
  803.             UserControl.CurrentY = (100 - UserControl.TextHeight(txtBarTxt)) / 2
  804.             'Get X coord to put the text.
  805.             UserControl.CurrentX = 50 - UserControl.TextWidth(txtBarTxt) / 2
  806.             'Print bar text.
  807.             UserControl.Print txtBarTxt
  808.         End If
  809.         'Reset to pixels mode.
  810.         UserControl.ScaleMode = 3
  811.     End If
  812. End Sub
  813. Public Sub PlayWav()
  814.     'If the percentage has reached 100 and the flag to play
  815.     'a sound is on, then play the wav file.
  816.     If mvarPercent = 100 And mvarPlaySound Then
  817.         'If the file can be found then play it.
  818.         If Dir(mvarSoundToPlay) <> "" Then
  819.             'If we're supposed to wait for the sound to finish
  820.             'then play the sound sync'ed.
  821.             If mvarWaitForSound Then
  822.                 sndPlaySound mvarSoundToPlay, SND_SYNC
  823.             Else
  824.                 sndPlaySound mvarSoundToPlay, SND_ASYNC
  825.             End If
  826.         End If
  827.     End If
  828. End Sub
  829.